# -* - coding: UTF-8 -* -
#
#reload(sys)
#sys.setdefaultencoding('utf8')
#工厂中心，负责分配任务

import threading,string
from time import sleep
from rabbitmq_queue import *
from redis_queue import *
import logging

#从外部队列读取消息放入内部对列
class ServerFactory():  
	def __init__(self,defaultDriver):
		self.driver = defaultDriver
		self.factoryList = {}
		self.register('redis',RedisQueue)
		self.register('rabbit',RabbitmqQueue)
	
	#读取暂存的命令
	def register(self,driver,factory):
		self.factoryList[driver]=factory

	def get(self,driver=''):
		if driver:
			return self.factoryList[driver]	
		else:
			return self.factoryList[self.driver]	

	def create(self,config,name,driver=''):
		Server = self.get(driver)
		return Server(config,name)
#factory = ServerFactory('redis')
#factory.create({},'rpc')